import React, { useCallback, useEffect, useState } from 'react';
import useBasisCash from './useBasisCash';
import config from '../config';

const useNycLpInfo = (token:string,v2:boolean):any => {
  const [stat, setStat] = useState({});
  const basisCash = useBasisCash();

  const fetchLiquidityOracle = useCallback(async () => {
      const stat = await basisCash.getNycLpStat(token);
      setStat(stat);
  }, [basisCash,v2]);

  useEffect(() => {
    fetchLiquidityOracle().catch((err) => console.error(`Failed to fetch SNB price: useCashStats ${err.stack}`));
    const refreshInterval = setInterval(fetchLiquidityOracle, config.refreshInterval);
    return () => clearInterval(refreshInterval);
  }, [basisCash,v2]);

  return stat;
};

export default useNycLpInfo;
